package com.ruoyi.xuexiao.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.xuexiao.domain.entity.BasicRegion;
import com.ruoyi.xuexiao.domain.entity.WtCztzV3;
import com.ruoyi.xuexiao.domain.param.*;
import com.ruoyi.xuexiao.domain.param.RwTzV3VParam;
import com.ruoyi.xuexiao.service.AnalysisService;
import com.ruoyi.xuexiao.service.RwTzV3Service;
import com.ruoyi.xuexiao.service.WtCztzV3Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

/**
 * 统计分析
 * @author 田江余
 * @date: 2024-5-27 19:44:10
 */
@Api(tags = "统计分析模块")
@RestController
@RequestMapping("/analysis")
public class AnalysisController {

    @Autowired
    private AnalysisService analysisService;

    @Autowired
    private WtCztzV3Service wtCztzV3Service;

    @Autowired
    private RwTzV3Service rwTzV3Service;

    /**
     * 上/下半年常规任务填报进度
     * @author 田江余
     * @param rwTzV3DTOS
     * @param supervise
     * @return
     */
    @ApiOperation("上/下半年常规任务填报进度")
    @GetMapping("/inTheSecond")
    public R<List<RwTzV3VParam>> inTheSecond(ArrayList<RwTzV3VParam> rwTzV3DTOS, SuperviseParam supervise) {
        return R.ok(analysisService.inTheSecondHalfOfTheYear(rwTzV3DTOS,supervise));
    }


    /**
     * 上/下半年常规任务审核进度
     * @param rwTzV3DTOS
     * @author 田江余
     * @return
     */
    @ApiOperation("上/下半年常规任务审核进度")
    @GetMapping("/halfOf")
    public R<List<RwTzV3VParam> > HalfOf(ArrayList<RwTzV3VParam> rwTzV3DTOS, SuperviseParam supervise) {
        return R.ok(analysisService.inTheSecondHalfOf(rwTzV3DTOS,supervise));
    }
    /**
     * 上/下半年常规任务填报进度(县级
     * @author 田江余
     * @return
     */
    @ApiOperation("上/下半年常规任务填报进度(县级)")
    @GetMapping("/andCounty")
    public R<List<BasicRegion>> andCounty(SuperviseParam supervise) {
        return R.ok(analysisService.getCountyRegionsByCityName(supervise));
    }

    /**
     * 上/下半年常规任务审核进度(县级)
     * @author 田江余
     * @return
     */
    @ApiOperation("上/下半年常规任务审核进度(县级)")
    @GetMapping("/regionsByCityName")
    public R<List<BasicRegion> > regionsByCityName(SuperviseParam supervise) {
        return R.ok(analysisService.regionsByCityName(supervise));
    }

    /**
     * 任务类型统计(市级)
     * @author 田江余
     * @return
     */
    @ApiOperation("任务类型统计(市级)")
    @GetMapping("/countyRegions")
    public R<List<BasicRegion>> countyRegionsByCityName(SuperviseParam supervise) {
        return R.ok(analysisService.countyRegionsByCityName(supervise));
    }

    /**
     * 任务类型统计   (县级)
     * @author 田江余
     * @return
     */
    @ApiOperation("任务类型统计(县级)")
    @GetMapping("/countyRegion")
    public R<List<BasicRegion>> countyRegion(SuperviseParam supervise) {
        return R.ok(analysisService.countyRegionsBy(supervise));
    }

    /**
     * 查询行政区
     * @author 田江余
     * @return
     */
    @ApiOperation("查询行政区")
    @GetMapping("/getXian")
    public R<List<BasicRegion>> getXianBy() {
        return R.ok(analysisService.getXianBy());
    }

    /**
     * 问题处置统计-统计类型
     * @author 田江余
     * @return
     */
    @ApiOperation("问题处置统计-统计类型")
    @GetMapping("/getLeiXin")
    public R<List<BasicRegion>> getLeiXing(SuperviseParam supervise) {
        return R.ok(wtCztzV3Service.getCountyRegionsByCityName(supervise));
    }

    /**
     * 问题类型统计-统计类型
     * @author 田江余
     * @return
     */
    @ApiOperation("问题类型统计-统计类型")
    @GetMapping("/getWt")
    public R<List<WtCztzV3>> getWt(SuperviseParam supervise) {
        return R.ok(wtCztzV3Service.countyRegionsByCityName(supervise));
    }

    /**
     * 上/下半年每月填报统计
     * @author 田江余
     */
    @ApiOperation("上/下半年每月填报统计")
    @GetMapping("/selectMyY")
    public R<List<RwTzV3VParam>> selectMyY(SuperviseParam supervise) {
        return R.ok(rwTzV3Service.selectMyY(supervise));
    }

    /**
     * 上/下半年每月审核统计
     * @author 田江余
     */
    @ApiOperation("上/下半年每月审核统计")
    @GetMapping("/selectSh")
    public R<List<RwTzV3VParam>> selectSh(SuperviseParam supervise) {
        return R.ok(rwTzV3Service.selectSh(supervise));
    }



    /**
     * 常规任务填报进度导出
     * @author 田江余
     */
    @ApiOperation("常规任务填报进度导出")
    @PostMapping("/exportExtractAnalysis")
    public void exportExtractData(HttpServletResponse response,@RequestBody List<RwTzV3Param> rwTzV3DTOS) throws UnsupportedEncodingException {
        //设置请求体
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("常规任务填报进度.xlsx", "UTF-8"));
        ExcelUtil<RwTzV3Param> util = new ExcelUtil<>(RwTzV3Param.class);
        util.exportExcel(response, rwTzV3DTOS, "统计分析");
    }

    /**
     * 常规任务审核进度导出
     * @author 田江余
     */
    @ApiOperation("常规任务审核进度导出")
    @PostMapping("/exportExtract")
    public void exportExtract(HttpServletResponse response, @RequestBody List<StatisticsParam> rwTzV3DTOS) throws UnsupportedEncodingException {
        //设置请求体
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("常规任务审核进度.xlsx", "UTF-8"));
        ExcelUtil<StatisticsParam> util = new ExcelUtil<>(StatisticsParam.class);
        util.exportExcel(response, rwTzV3DTOS, "统计分析");
    }

    /**
     * 常规任务填报进度(县级)导出
     * @author 田江余
     */
    @ApiOperation("常规任务填报进度(县级)导出")
    @PostMapping("/XjRwExportExtract")
    public void xjRwExportExtract(HttpServletResponse response, @RequestBody List<XjRwTzV3Param> xjRwTzV3Params) throws UnsupportedEncodingException {
        //设置请求体
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("常规任务填报进度(县级).xlsx", "UTF-8"));
        ExcelUtil<XjRwTzV3Param> util = new ExcelUtil<>(XjRwTzV3Param.class);
        util.exportExcel(response, xjRwTzV3Params, "统计分析");
    }

    /**
     * 常规任务审核进度(县级)导出
     * @author 田江余
     */
    @ApiOperation("常规任务审核进度(县级)导出")
    @PostMapping("/XjRwExtract")
    public void xjRwExtract(HttpServletResponse response, @RequestBody List<ShRwTzV3Param> xjRwTzV3Params) throws UnsupportedEncodingException {
        //设置请求体
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("常规任务审核进度(县级).xlsx", "UTF-8"));
        ExcelUtil<ShRwTzV3Param> util = new ExcelUtil<>(ShRwTzV3Param.class);
        util.exportExcel(response, xjRwTzV3Params, "统计分析");
    }

    /**
     * 任务类型统计(市级)导出
     * @author 田江余
     */
    @ApiOperation("任务类型统计(市级)导出")
    @PostMapping("/RwLxExtract")
    public void rwLxExtract(HttpServletResponse response, @RequestBody List<SjBasicRegionParam> xjRwTzV3Params) throws UnsupportedEncodingException {
        //设置请求体
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("任务类型统计(市级).xlsx", "UTF-8"));
        ExcelUtil<SjBasicRegionParam> util = new ExcelUtil<>(SjBasicRegionParam.class);
        util.exportExcel(response, xjRwTzV3Params, "统计分析");
    }

    /**
     * 任务类型统计(县级)导出
     * @author 田江余
     */
    @ApiOperation("任务类型统计(县级)导出")
    @PostMapping("/RwXjExtract")
    public void RwXjExtract(HttpServletResponse response, @RequestBody List<BasicRegionParam> xjRwTzV3Params) throws UnsupportedEncodingException {
        //设置请求体
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("任务类型统计(县级).xlsx", "UTF-8"));
        ExcelUtil<BasicRegionParam> util = new ExcelUtil<>(BasicRegionParam.class);
        util.exportExcel(response, xjRwTzV3Params, "统计分析");
    }

    /**
     * 上/下半年每月填报统计导出
     * @author 田江余
     */
    @ApiOperation("上/下半年每月填报统计导出")
    @PostMapping("/RwXjMonth")
    public void RwXjMonth(HttpServletResponse response, @RequestBody List<MonthlyParam> rwTzV3VoList) throws UnsupportedEncodingException {
        //设置请求体
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("上/下半年每月填报统计.xlsx", "UTF-8"));
        ExcelUtil<MonthlyParam> util = new ExcelUtil<>(MonthlyParam.class);
        util.exportExcel(response, rwTzV3VoList, "统计分析");
    }

    /**
     * 上/下半年每月审核统计导出
     * @author 田江余
     */
    @ApiOperation("上/下半年每月审核统计导出")
    @PostMapping("/RwShMonth")
    public void RwShMonth(HttpServletResponse response, @RequestBody List<MonthlyReporting> rwTzV3VoList) throws UnsupportedEncodingException {
        //设置请求体
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("上/下半年每月审核统计.xlsx", "UTF-8"));
        ExcelUtil<MonthlyReporting> util = new ExcelUtil<>(MonthlyReporting.class);
        util.exportExcel(response, rwTzV3VoList, "统计分析");
    }


    /**
     * 上/下半年问题处置统计导出
     * @author 田江余
     */
    @ApiOperation("上/下半年问题处置统计导出")
    @PostMapping("/RwWtMonth")
    public void RwWtMonth(HttpServletResponse response, @RequestBody List<ProblemHandling> rwTzV3VoList) throws UnsupportedEncodingException {
        //设置请求体
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("上/下半年问题处置统计.xlsx", "UTF-8"));
        ExcelUtil<ProblemHandling> util = new ExcelUtil<>(ProblemHandling.class);
        util.exportExcel(response, rwTzV3VoList, "统计分析");
    }

    /**
     * 问题类型统计-统计类型
     * @author 田江余
     * @return
     */
    @ApiOperation("问题类型统计-统计类型")
    @PostMapping("/RwWtLxMonthEs")
    public void RwWtLxMonth(HttpServletResponse response, @RequestBody List<ProblemHand> rwTzV3VoList) throws UnsupportedEncodingException {
        //设置请求体
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("上/下半年问题类型统计.xlsx", "UTF-8"));
        ExcelUtil<ProblemHand> util = new ExcelUtil<>(ProblemHand.class);
        util.exportExcel(response, rwTzV3VoList, "统计分析");
    }
}